package top.meeting.room.module.book.query;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import com.xiaoleilu.hutool.date.DateUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Date;

/**
 * Created by Lyt on 2017/9/11.
 */
@Data
public class BookQuery {

    public BookQuery(String dateStr) {
        Calendar cal = Calendar.getInstance();
        try {
            cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(dateStr));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int d = 0;
        if (cal.get(Calendar.DAY_OF_WEEK) == 1) {
            d = -6;
        } else {
            d = 2 - cal.get(Calendar.DAY_OF_WEEK);
        }
        cal.add(Calendar.DAY_OF_WEEK, d);
        // 所在周开始日期
        String firstDateStr = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        Date firstDate = DateUtil.parse(firstDateStr);
        cal.add(Calendar.DAY_OF_WEEK, 6);
        // 所在周结束日期
        String lastDateStr = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
        Date lastDate = DateUtil.parse(lastDateStr);
        this.firstDate = firstDate.getTime();
        this.lastDate = lastDate.getTime();
    }

    public BookQuery() {
    }

    private Long firstDate;
    private Long lastDate;
    private String params;
    private Integer page;
    private Integer size;
    private String status;
    private Date currTime;
    private Long bookDate;
    private String roomId;
}
